/*-----------------------------------------------------------------------+
 | de.klenkse.eclipse.ftpsync
 |                                                                       |
   $Id: codetemplates.xml 18709 2009-03-06 13:31:16Z hummelb $            
 |                                                                       |
 | Copyright (c)  2010-2010 Klenk-SE                                 |
 |                                                                       |
 +-----------------------------------------------------------------------*/
package de.klenkse.eclipse.ftpsync.synchronizer;

import org.eclipse.core.resources.IResourceDelta;

/**
 * Factory for creating new commands.
 */
public abstract class ResourceCommandFactory {
	/**
	 * Generates an instance of a {@link ResourceCommand} for the given
	 * {@link IResourceDelta}.
	 */
	public static ResourceCommand getCommandForDelta(IResourceDelta delta,
			String relativePath) {
		if (delta.getKind() == IResourceDelta.ADDED) {
			System.out.println("Resource " + delta.getResource() + " added.");
			return new ResourceAddCommand(delta.getResource(), relativePath);
		} else if (delta.getKind() == IResourceDelta.REMOVED) {
			System.out.println("Resource " + delta.getResource() + " removed.");
			return new ResourceRemoveCommand(delta.getResource(), relativePath);
		} else if (delta.getKind() == IResourceDelta.CHANGED) {
			if (delta.getFlags() == IResourceDelta.CONTENT
					|| delta.getFlags() == IResourceDelta.REPLACED) {
				System.out.println("Resource " + delta.getResource()
						+ " content changed.");
				return new ResourceAddCommand(delta.getResource(), relativePath);
			}
		}
		return new NoOpCommand(delta, relativePath);
	}
}
